#include "util.h"
#include "Class.h"
#include <stdlib.h>
#include <string.h>
//actually creates XClass
Class* createClass(Image* image,string name){
    Class* cls=(Class*)image->clsXClass->newInstance();
    cls->setName(name);
    return cls;
}
void printObject(Image* i,Object* o){
    printf("%s",inspectString(o->send(i,"toString",0,NULL)));
}

Object* makeInteger(Image* i,int val){
   Object* r=i->clsInteger->newInstance(false);
   int* pr=(int*)r->dataAt(INT_OBJECT_DATA_OFFSET);
   *pr=val;
   return r;
}
Object* makeBoolean(Image* i,bool val){
   Object* r=i->clsBoolean->newInstance(false);
   bool* pr=(bool*)r->dataAt(BOOLEAN_OBJECT_DATA_OFFSET);
   *pr=val;
   return r;
}
Object* makeString(Image* i,char* val){
    int len=strlen(val)+1;
   Object* r=(Object*)i->alloc(STRING_OBJECT_DATA_OFFSET+len);
   i->clsString->initializeObject(r,false);
   int* pr=(int*)r->dataAt(STRING_OBJECT_LENGTH_OFFSET);
   *pr=len-1;
   char* data=(char*)r->dataAt(STRING_OBJECT_DATA_OFFSET);
   strcpy(data,val);
   return r;
}
int inspectInteger(Object* o){
   int* pr=(int*)o->dataAt(INT_OBJECT_DATA_OFFSET);
   return *pr;
}
bool inspectBoolean(Object* o){
   bool* pr=(bool*)o->dataAt(BOOLEAN_OBJECT_DATA_OFFSET);
   return *pr;
}
char* inspectString(Object* o){
    char* pr=(char*)o->dataAt(STRING_OBJECT_DATA_OFFSET);
   return pr;
}